package com.ruoyi.client.vo;

/**
 * <简述>
 * <详细描述>
 *
 * @author syf
 * @date 2025年03月12日 12:05
 */

import com.alibaba.fastjson.JSON;

import java.nio.charset.StandardCharsets;
import java.util.Map;

import static java.util.Objects.requireNonNull;

/**
 * Http请求内容
 * @author jmdhappy
 * @site syf
 * @date 2021-06-08 11:00
 */
public class HttpContent {

    byte[] byteArrayContent;

    String contentType;

    private HttpContent(byte[] byteArrayContent, String contentType) {
        this.byteArrayContent = byteArrayContent;
        this.contentType = contentType;
    }

    public String stringContent() {
        return new String(this.byteArrayContent,StandardCharsets.UTF_8);
    }

    public static HttpContent buildJSONContent(Map<String, Object> params) {
        requireNonNull(params);

        return new HttpContent(
            createJSONString(params).getBytes(StandardCharsets.UTF_8),
            String.format("application/json; charset=%s","UTF-8"));
    }

    private static String createJSONString(Map<String, Object> params) {
        return JSON.toJSONString(params);
    }

}
